package com.zhangyu.shadow.core.net.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

/**
 * @author zhangyu
 * @date 2018/7/3
 */

public class NetBroadcastReceiver extends BroadcastReceiver {
    private OnNetChangeListener mChangeListener;

    public NetBroadcastReceiver(OnNetChangeListener listener) {
        mChangeListener = listener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
            if (mChangeListener != null) {
                mChangeListener.onNetChange();
            }
        }
    }

    public interface OnNetChangeListener {
        void onNetChange();
    }
}
